<!--
 * Description: SupplyCloud主页面
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Dongxu.Ni
 * Date: 2020/04/14 02:52
-->

<template>
  <BaseWrap>
    <!-- 查询条件 -->
    <BaseFunc
      :is-requesting="isRequesting"
      :query-form="queryForm"
      :visible.sync="advanceOptionDrawer"
      @query="query"
    >
      <!-- 按钮 -->
      <template slot="btn">
        <el-button
          v-if="$hasPer('add')"
          class="btn-custom"
          icon="el-icon-circle-plus-outline"
          plain
          size="mini"
          type="primary"
          @click="addDialogVisible = true"
        >
          {{ $t('button.add') }}
        </el-button>
      </template>

      <!--抽屉内部查询表单-->
      <template>
        <el-form class="g-advance-drawer-form" label-width="120px" :model="queryForm" size="medium">
          <el-row>
            <!--pn-->
            <el-col :span="6">
              <el-form-item label="PN">
                <el-input v-model="queryForm.pn" clearable />
              </el-form-item>
            </el-col>

            <!--vendor-->
            <el-col :span="6">
              <el-form-item label="Vendor">
                <el-input v-model="queryForm.vendor" clearable />
              </el-form-item>
            </el-col>

            <!--sourceCode-->
            <el-col :span="6">
              <el-form-item label="SourceCode">
                <el-input v-model="queryForm.sourceCode" clearable />
              </el-form-item>
            </el-col>

            <!--quarter-->
            <el-col :span="6">
              <el-form-item label="Quarter">
                <el-input v-model="queryForm.quarter" clearable />
              </el-form-item>
            </el-col>

            <!--baseUnitPrice-->
            <el-col :span="6">
              <el-form-item label="BaseUnitPrice">
                <el-input v-model="queryForm.baseUnitPrice" clearable />
              </el-form-item>
            </el-col>

            <!--fiscalYear-->
            <el-col :span="6">
              <el-form-item label="FiscalYear">
                <el-input v-model="queryForm.fiscalYear" clearable />
              </el-form-item>
            </el-col>

            <!--outTapeSavingFin-->
            <el-col :span="6">
              <el-form-item label="OutTapeSavingFin">
                <el-input v-model="queryForm.outTapeSavingFin" clearable />
              </el-form-item>
            </el-col>

            <!--outTapeSavingScm-->
            <el-col :span="6">
              <el-form-item label="OutTapeSavingScm">
                <el-input v-model="queryForm.outTapeSavingScm" clearable />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </template>
    </BaseFunc>

    <!--报价commodity数据表格-->
    <BaseTable
      :is-requesting="isRequesting"
      :page-number.sync="pageNumber"
      :page-size.sync="pageSize"
      :table-data="tableData"
      :total="total"
      @query="query"
    >
      <template slot="header">
        <!--序号列-->
        <el-table-column align="center" fixed :label="$t('table.NO')" min-width="50px">
          <template slot-scope="scope">
            <span>{{ scope.$index + 1 }}</span>
          </template>
        </el-table-column>
      </template>

      <template>
        <!--pn-->
        <el-table-column
          align="center"
          label="PN"
          min-width="200px"
          prop="pn"
          :sort-method="$sortByLower"
          sortable
        />
        <!--vendor-->
        <el-table-column align="center" label="Vendor" min-width="150px" prop="vendor" sortable />
        <!--sourceCode-->
        <el-table-column
          align="center"
          label="SourceCode"
          min-width="150px"
          prop="sourceCode"
          sortable
        />
        <!--quarter-->
        <el-table-column align="center" label="Quarter" min-width="200px" prop="quarter" sortable />
        <!--baseUnitPrice-->
        <el-table-column
          align="center"
          label="baseUnitPrice"
          min-width="200px"
          prop="baseUnitPrice"
          sortable
        />
        <!--fiscalYear-->
        <el-table-column
          align="center"
          label="fiscalYear"
          min-width="150px"
          prop="fiscalYear"
          sortable
        ></el-table-column>
        <!--outTapeSavingFin-->
        <el-table-column
          align="center"
          label="OutTapeSavingFin"
          min-width="200px"
          prop="outTapeSavingFin"
          sortable
        />
        <!--outTapeSavingScm-->
        <el-table-column
          align="center"
          label="OutTapeSavingScm"
          min-width="200px"
          prop="outTapeSavingScm"
          sortable
        />
        <!--createTime 创建时间-->
        <el-table-column
          align="center"
          :label="$t('SupplyCloud.createDate')"
          min-width="200px"
          prop="createTime"
          sortable
        />
        <!--updater 更新者-->
        <!-- <el-table-column
          align="center"
          :label="$t('SupplyCloud.updater')"
          min-width="200px"
          prop="updater"
          sortable
        >
          <template slot-scope="scope">
            <span>
              {{ $store.getters['user/getUserNameById'](scope.row.updater) || $t('result.none') }}
            </span>
          </template>
        </el-table-column> -->
      </template>

      <!-- 右浮动 -->
      <template slot="end">
        <!--操作列-->
        <el-table-column
          align="center"
          fixed="right"
          :label="$t('table.operate')"
          min-width="150px"
        >
          <template slot-scope="scope">
            <el-button
              v-if="$hasPer('edit')"
              size="mini"
              type="text"
              @click="rowEdit(scope.$index, scope.row)"
            >
              <i class="el-icon-edit el-icon--right"></i>
              {{ $t('button.edit') }}
            </el-button>
            <el-button
              v-if="$hasPer('delete')"
              size="mini"
              type="text"
              @click="rowDelete(scope.$index, scope.row)"
            >
              <i class="el-icon-delete el-icon--right"></i>
              {{ $t('button.delete') }}
            </el-button>
          </template>
        </el-table-column>
      </template>
    </BaseTable>

    <!--新增对话框-->
    <BaseDialog
      v-if="addDialogVisible"
      :title="$t('dialog.add')"
      :visible.sync="addDialogVisible"
      width="55%"
    >
      <QuarterPriceAdd @cancel="addDialogVisible = false" @save="afterAddSave" />
    </BaseDialog>

    <!--编辑对话框-->
    <BaseDialog
      v-if="editDialogVisible"
      :title="$t('dialog.edit')"
      :visible.sync="editDialogVisible"
      width="55%"
    >
      <QuarterPriceEdit
        :input-data="currentEditRow"
        @cancel="editDialogVisible = false"
        @save="afterEditSave"
      />
    </BaseDialog>
  </BaseWrap>
</template>

<script>
import { quarterPriceGRPageList, quarterPriceGRDelete } from '@/api/spendingSaving/spendingSaving'
import QuarterPriceAdd from './components/QuarterPriceAdd'
import QuarterPriceEdit from './components/QuarterPriceEdit'

export default {
  name: 'QuarterPriceGR',
  components: { QuarterPriceAdd, QuarterPriceEdit },
  props: {},
  data() {
    return {
      // 正在查询
      isRequesting: false,
      // 高级查询选项抽屉弹出标识
      advanceOptionDrawer: false,
      // 页码
      pageNumber: 1,
      // 页展示行数
      pageSize: 10,
      // 总行数
      total: 0,
      // 表格数据
      tableData: [],
      // 查询表单对象
      queryForm: {
        baseUnitPrice: '',
        createTime: '',
        fiscalYear: '',
        outTapeSavingFin: '',
        outTapeSavingScm: '',
        pn: '',
        quarter: '',
        sourceCode: '',
        vendor: ''
      },
      // 新增对话框可见标识
      addDialogVisible: false,
      // 编辑对话框可见标识
      editDialogVisible: false,
      // 当前编辑行的数据
      currentEditRow: {}
    }
  },
  computed: {},
  watch: {},
  created() {
    this.pageDataInit()
  },
  mounted() {},
  methods: {
    /* 页面数据初始化*/
    pageDataInit() {
      this.query()
    },
    /* 查询表格数据*/
    async query() {
      try {
        this.isRequesting = true
        this.advanceOptionDrawer = false
        const res = await quarterPriceGRPageList({
          pageSize: this.pageSize,
          pageNumber: this.pageNumber,
          pageCondition: this.queryForm
        })
        this.tableData = res.data.list
        this.total = res.data.total
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    /* 行记录编辑*/
    rowEdit(index, row) {
      this.currentEditRow = row
      this.editDialogVisible = true
    },
    /* 行记录删除 */
    async rowDelete(index, row) {
      try {
        await this.$confirmBox(this.$t('button.delete'), 'error')
        this.isRequesting = true
        await quarterPriceGRDelete({ pnId: row.pnId })
        this.query()
        // this.$store.dispatch('commodity/initCommodityCollects')
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    // 新增保存之后
    afterAddSave() {
      this.addDialogVisible = false
      this.query()
      // this.$store.dispatch('commodity/initCommodityCollects')
    },
    // 修改保存之后
    afterEditSave() {
      this.editDialogVisible = false
      this.query()
      // this.$store.dispatch('commodity/initCommodityCollects')
    }
  }
}
</script>

<style scoped></style>
